package com.itheima.jobs;

import cn.hutool.core.collection.CollectionUtil;
import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPool;

import java.util.Date;
import java.util.Set;

@Component
public class DeleteImage {

    @Autowired
    JedisPool jedisPool;

    public void run(){
        //数量多的集合key在前面
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if(CollectionUtil.isNotEmpty(sdiff)){
            for (String name : sdiff) {
                //删除七牛图片
                QiniuUtils.deleteFileFromQiniu(name);
                //删除redis里面没用的图片
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,name);
            }
        }
    }

}
